﻿using Awsc.DataAcquisitionSys.Core.Databases;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Awsc.DataAcquisitionSys.Core.Services.SentinelMode
{
    public interface ISentinelService
    {
        Task OpenSentinelModeAsync();
        Task CloseSentinelModeAsync();
    }
    public class SentinelService : ISentinelService
    {
        private readonly ISentinelRepository sentinelRepository;
        private readonly SentinelDataWriter sentinelDataWriter;

        public SentinelService(ISentinelRepository sentinelRepository, SentinelDataWriter sentinelDataWriter)
        {
            this.sentinelRepository = sentinelRepository;
            this.sentinelDataWriter = sentinelDataWriter;
        }

        public async Task OpenSentinelModeAsync()
        {
            var tableName = GenerateTableName(DateTime.Now);
            await sentinelRepository.CreateSentinelTableAsync(tableName);
            sentinelDataWriter.StartRecording(tableName);
        }
        public async Task CloseSentinelModeAsync()
        {
            sentinelDataWriter.StopRecording();
            
        }
        private string GenerateTableName(DateTime dateTime)
        {
            return $"Sentinel_{dateTime:yyyy_MM_dd}";
        }

    }
}
